﻿<#
.SYNOPSIS  
    Removes Project Web Instances.  
.DESCRIPTION  
    
.NOTES
    The Project Server cmdlets do not delete SQL server databases when web instances are removed.  
    Do not manually delete them, just restore over them on the next practice upgrade.
.LINK  
    http://7up.codeplex.com 
#>

Write-Host ("   Removing Project Web Instances ({0})..." -f [DateTime]::Now.ToString())

#add SharePoint snap in
if ((Get-PSSnapin -Name  Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null) 
{ 
    Add-PsSnapin  Microsoft.SharePoint.PowerShell 
}

#get config
$config = [xml](Get-Content Upgrade.xml)

#remove project web instances
foreach($psa in $config.Settings.ServiceApplications.ProjectServiceApplications.ProjectServiceApplication)
{
	if($psa -ne $null)
	{
		foreach($pwi in $psa.ProjectWebInstances.ProjectWebInstance)
		{
			$instance = (Get-SPProjectWebInstance -Url $pwi.Url -ErrorAction SilentlyContinue)
			if($instance -eq $null)
			{
				Write-Host ("      Skipping '{0}' because it does not exist." -f $pwi.Url)
			}
			else 
			{
				Write-Host ("      Removing '{0}'..." -f $pwi.Url)
				Remove-SPProjectWebInstance -Url $pwi.Url -KeepSiteCollection:$false -Wait
			}
					
		}
					
	}
}
